
<template>
  <views class="gen_log">
    <viewTitle :title="'付款记录'" :border="false"></viewTitle>
    <!-- 搜索栏  企业端-代理商端-服务商端 -->
    <div class="search flex flexC">
      <!-- 客户编号-客户名称-批次编号-订单号-业务状态-收款户号-收款账号-充值时间 -->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR center">
          <div class="their_facilitator flex flexR center">
            <el-form-item label="企业编号:">
              <el-input v-model="all.form.enterprise_sn" placeholder="请输入企业编号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="bank_statement flex flexR center">
            <el-form-item label="企业名称:">
              <el-input v-model="all.form.enterprise_name" placeholder="请输入企业名称" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="customer_number flex flexR center">
            <el-form-item label="批次编号:">
              <el-input
                v-model="all.form.enterprise_order_sn"
                placeholder="请输入批次编号"
                :clearable="true"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR center">
          <div class="pay_state flex flexR center">
            <el-form-item label="业务状态:">
              <el-select v-model="all.form.status" clearable placeholder="请选择">
                <el-option
                  v-for="item in all.form.status_list"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- 收款账号 -->
          <div class="their_facilitator flex flexR center">
            <el-form-item label="收款账号:">
              <el-input v-model="all.form.rec_bank_code" placeholder="请输入收款户号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <!-- 收款户号 -->
          <div class="bank_statement flex flexR center">
            <el-form-item label="收款户名:">
              <el-input v-model="all.form.rec_bank_account" placeholder="请输入收款户名" :clearable="true"></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <!-- 充值时间  按钮 (查询、重置、导出列表)-->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="flex flexR">
        <div class="bank_statement flex flexR center">
          <el-form-item label="订单号:">
            <el-input
              v-model="all.form.enterprise_order_ext_sn"
              placeholder="请输入订单号"
              :clearable="true"
            ></el-input>
          </el-form-item>
        </div>
        <div class="pay_btn flex">
          <!-- 充值时间 -->
          <div class="pay_time flex flexR center">
            <el-form-item label="提交时间:">
              <el-date-picker
                v-model="create_time"
                type="datetimerange"
                align="right"
                :default-time="['0:00:00','23:59:59']"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </div>
        </div>
        </div>
      </el-form>
      <!-- 按钮（查询、重置、导出列表）   -->
      <el-form ref="form" label-width="auto" :style="{padding:'0 15px'}" :inline="true">
        <div class="flex flexR">
          <div class="flex flexR center">
            <el-form-item label="完成时间:">
              <el-date-picker
                v-model="pay_time"
                type="datetimerange"
                align="right"
                :default-time="['0:00:00','23:59:59']"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </div>
          <el-form-item>
            <el-button type="primary" @click="query" icon="el-icon-search">查看</el-button>
            <el-button @click="reset" icon="el-icon-refresh">重置</el-button>
            <el-button type="danger" icon="el-icon-download" @click="exportExcel">导出列表</el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>

    <div class="search_input flex flexR center" >
      <div :style="{marginLeft:'15px'}" class="show-title-money flex flexR">
        <div class="flex flexR">
          <div>交易笔数</div>
          <div class="price">{{pagination.total_count}}</div>
          <div>笔</div>
        </div>
        <div class="flex flexR">
          <div>交易金额(元)</div>
          <div class="price">￥{{pagination.summy ? $splitK(pagination.summy) : ''}}</div>
        </div>
      </div>
    </div>

    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="all.tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column fixed type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="enterprise_order_sn" label="批次编号" ></el-table-column>
        <el-table-column prop="enterprise_order_ext_sn" label="订单号" ></el-table-column>
        <el-table-column prop="enterprise_sn" label="企业编号" ></el-table-column>
        <el-table-column prop="enterprise_name" label="企业名称" width="150"></el-table-column>
        <el-table-column prop="facilitator_name" label="服务商名称" width="150"></el-table-column>
        <el-table-column prop="create_time" label="提交时间" width="160"></el-table-column>
        <el-table-column
          :formatter="(row) =>{return row.pay_time > 0 ?this.$moment(row.pay_time*1000).format('YYYY-MM-DD HH:MM:SS'):'';}"
          label="完成时间"
          width="160"
        ></el-table-column>
        <el-table-column prop="real_money" label="交易金额" width="120"></el-table-column>
        <el-table-column prop="rec_bank_account" label="收款户名" width="100"></el-table-column>
        <el-table-column prop="rec_bank_code" label="收款账号" ></el-table-column>
        <el-table-column prop="status_desc" label="业务状态" width="140"></el-table-column>
        <el-table-column prop="pay_err_msg" label="备注" width="140"></el-table-column>
        <el-table-column prop="zip" label="操作" fixed="right" v-if="isLook || isUpdate">
          <div class="table_operation" slot-scope="scope">
            <el-button type="primary" @click="toDetail(scope)" v-if="isLook">详情</el-button>
            <el-button
              type="info"
              v-if="scope.row.payment_status==1"  @click="updStatus(scope.row.enterprise_order_ext_id)"
            >更新</el-button>
            <!--<el-button type="error" v-if="scope.row.payment_status==2 && $store.state.terrace == 3"  @click="reSend(scope.row.enterprise_order_ext_id)">重发</el-button>-->
          </div>
        </el-table-column>
      </el-table>
      <div class="paging flex flexR">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="total, sizes,prev, pager, next, jumper"
          @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
          @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>



<script>
import  {mapGetters} from 'vuex'

export default {
  data() {
    return {
      //  三段综合  企业端  代理商端  服务商端
      all: {
        form: {
          enterprise_sn: "", // 客户编号
          enterprise_name: "", // 客户名称
          enterprise_order_sn: "", // 批次编号
          enterprise_order_ext_sn: "", // 订单号
          status: "", // 状态
          status_list: [
            {
              value: "0",
              label: "待审核"
            },
            {
              value: "1",
              label: "企业内部审核通过"
            },
            // {
            //   value: "2",
            //   label: "服务商审核通过"
            // },
            {
              value: "4",
              label: "已全部打款"
            },
            {
              value: "5",
              label: "审核不通过"
            }
          ], // 状态列表
          rec_bank_code: "", // 收款账户
          rec_bank_account: "", // 收款户名
          created_time_start: "", // 交易开始时间
          created_time_end: "", // 交易结束时间
          bank_payment_sn: "" // 银行打款流水号
        },
        tableData: []
      },
      create_time: [], // 时间数组
      pay_time: [], // 时间数组
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      pagination: {
        page_start: 1,
        page_size: 10
      }, // 分页
      download_url: "" // 导出
    };
  },
  mounted() {
    this.getData(); // 付款记录列表
  },
  computed: {
    //实时计算要传输的编辑参数
    post_data() {
      let data = {},
        time_list = this.create_time || [];
      if (time_list && time_list.length > 0) {
        data.created_time_start = time_list[0]/1000;
        data.created_time_end = time_list[1]/1000;
      }
      if (this.pay_time && this.pay_time.length > 0) {
        data.pay_time_start = this.pay_time[0]/1000;
        data.pay_time_end = this.pay_time[1]/1000;
      }

      data.enterprise_sn = this.all.form.enterprise_sn; // 客户编号
      data.enterprise_name = this.all.form.enterprise_name; // 客户名称
      data.enterprise_order_sn = this.all.form.enterprise_order_sn; // 批次编号
      data.enterprise_order_ext_sn = this.all.form.enterprise_order_ext_sn; // 订单号
      data.status = this.all.form.status; // 状态
      data.rec_bank_code = this.all.form.rec_bank_code; // 收款账户
      data.rec_bank_account = this.all.form.rec_bank_account; // 收款户名
      data.bank_payment_sn = this.all.form.bank_payment_sn; // 银行打款流水号

      data.pagination = this.pagination;
      return data;
    },
    getTerrace() {
      //获取当前用户类型；1：企业、2：代理商、3：服务商
      return this.$store.state.terrace;
    },
    ...mapGetters(['getButtonPermission']),
    isLook(){
      return  this.getButtonPermission[this.$route.path] && this.getButtonPermission[this.$route.path].look ? 1 : 0;
    },
    isUpdate(){
      return  this.getButtonPermission[this.$route.path] && this.getButtonPermission[this.$route.path].update ? 1 : 0;
    }
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    // 付款记录-详情
    toDetail(scope) {
      this.$toRoutePath({
        path: "/gen_log/gen_log_detail",
        edit: true,
        query: {
          enterprise_order_ext_id: scope.row.enterprise_order_ext_id
        }
      });
    },
    // 获取付款记录列表
    getData() {
      //  服务商-付款记录
      if (this.$store.state.terrace == 3) {
        let data = this.$api.sendSync(
          this.$mapapi.f_orderListDischarge,
          this.post_data
        );
        this.pagination = data.data.pagination || {}; // 分页数据
        if (data.code != 200 && data.code != 501) {
          this.$message.error(data.msg);
          return;
        }
        this.all.tableData = data.data.list || []; // 列表
        this.download_url = data.data.download_url;
      }

      //  企业-付款记录
      if (this.$store.state.terrace == 1) {
        let data = this.$api.sendSync(
          this.$mapapi.e_orderListDischarge,
          this.post_data
        );
        this.pagination = data.data.pagination || {}; // 分页数据
        if (data.code != 200 && data.code != 501) {
          this.$message.error(data.msg);
          return;
        }
        console.log("付款记录企业端", data);
        this.all.tableData = data.data.list || [];
        this.download_url = data.data.download_url;
      }
    },
    // 分页触发
    handleSizeChange(data) {
      this.pagination.page_start = data;
    },
    changePage(data) {
      this.pagination.page_start = data;
    },
    //  重置
    reset() {
      this.all.form.enterprise_sn = ""; // 客户编号
      this.all.form.enterprise_name = ""; // 客户名称
      this.all.form.enterprise_order_sn = ""; // 批次编号
      this.all.form.enterprise_order_ext_sn = ""; // 订单号
      this.all.form.status = ""; // 状态
      this.all.form.rec_bank_code = ""; // 收款账户
      this.all.form.rec_bank_account = ""; // 收款户名
      this.all.form.created_time_start = ""; // 交易开始时间
      this.all.form.created_time_end = ""; // 交易结束时间
      this.all.form.bank_payment_sn = ""; // 银行打款流水号
      this.create_time = []; // 时间数组
      this.pay_time = []; // 时间数组
      this.getData();
    },
    //   查询
    query() {
      this.getData();
    },
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    updStatus(enterprise_order_ext_id) {
      this.$confirm("你确定要向银行查询么, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let { code, msg } = this.$api.sendSync(
            this.$mapapi.equeryExtIssuing,
            {
              enterprise_order_ext_id: enterprise_order_ext_id
            }
          );
          if (code != 200) {
            this.$message.error(msg);
            return;
          }
          this.getData();
          this.$message({
            type: "success",
            message: "已更新!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    reSend(enterprise_order_ext_id) {
      this.$confirm("你确定要向银行重新发起打款么, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let { code, msg } = this.$api.sendSync(this.$mapapi.frecheckIssuing, {
            enterprise_order_ext_id: enterprise_order_ext_id
          });
          if (code != 200) {
            this.$message.error(msg);
            return;
          }
          this.getData();
          this.$message({
            type: "success",
            message: "已更新!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    }
  },
  created() {}
};
</script>


<style lang="less" :scope="true"  src="@/style/issuing/gen_log.less" >
</style>
